package com.itheima.collection;

import com.itheima.domain.Student;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * 需求 使用Collection  存储并遍历学生
 * 1.创建学生类
 * 2.创建学生测试类
 * 2.1创建Collection集合
 * 2.2创建多个 学生对象
 * 2.3将学生对象加入集合中
 * 2.4遍历学生集合(迭代器 , 增强for)
 */
public class Test06 {

    public static void main(String[] args) {
        ////  2.1创建Collection集合
        Collection<Student> list= new ArrayList<>();
        //// * 	    2.2创建多个 学生对象
        Student student1 = new Student("鹿晗", 30);
        Student student2 = new Student("吴亦凡", 30);
        Student student3 = new Student("蔡徐坤", 22);
        Student student4 = new Student("黄子韬", 27);

        //// * 	    2.3将学生对象加入集合中
        list.add(student1);
        list.add(student2);
        list.add(student3);
        list.add(student4);
        //// * 	    2.4遍历学生集合(迭代器 , 增强for)
        //迭代器
        Iterator<Student> iterator = list.iterator();
        while(iterator.hasNext()){
            Student next = iterator.next();
            System.out.println(next);
        }
        System.out.println("-------------------------------");
        //增强for
        for (Student student : list) {
            System.out.println(student);
        }


    }
}
